<?php

namespace App\Http\Controllers\Front;

use App\Http\Controllers\Controller;
use App\Services\Form\initFormData as InitFormData;
use Illuminate\Http\Request;

class Asset extends Controller
{

    public $request;
    public $formData;
    public $breadMenuList;

    public function __construct(Request $request, InitFormData $formData)
    {
        $this->request = $request;
        $this->formData = $formData;
        $this->breadMenuList = config('front.bread_menu');

    }

    public function index()
    {

        $currentTabMenuList = config('front.tab_menu.' . parent::MENU_ASSET_COO);
        if ($this->request->input('type', 1) == 1) {
            $result = $this->formData->getFilterAssetCoo($this->request, $currentTabMenuList, parent::CODE_ASSET_FIND_PROJECT);
        } else if ($this->request->input('type') == 2) {
            $result = $this->formData->getFilterAssetCoo($this->request, $currentTabMenuList, parent::CODE_ASSET_FIND_MONEY);
        } else {
            $result = $this->formData->getFilterAssetCoo($this->request, $currentTabMenuList, parent::CODE_ASSET_FIND_PROJECT);
        }
        $dataList = $result ? $result['dataList'] : [];
        $pageCount = $dataList ? $result['pageCount'] : 1;

        if ($this->request->method() == 'POST') {
            $viewData = [
                'dataList' => $dataList,
                'infoUrl' => $this->returnInfoUrl(parent::MENU_ASSET_COO, ['type' => parent::MENU_ASSET_COO, 'flag' => $result['filterType']]),
            ];
            if ($result['filterType'] == 1) {
                return view('web.asset.list.project', $viewData);
            } elseif ($result['filterType'] == 2) {
                return view('web.asset.list.money', $viewData);
            }
        } else {
            $viewData = [
                'seo' => $this->returnSeoInfo(parent::MENU_ASSET_COO, $currentTabMenuList[$result['filterType']]['name']),
                'selectedMenu' => parent::MENU_ASSET_COO,

                'breadMenuList' => $this->breadMenuList,
                'currentBreadMenuList' => [parent::MENU_INDEX, parent::MENU_ASSET_COO],

                'currentTabMenuList' => $currentTabMenuList,
                'tabMenuMsg' => $currentTabMenuList[$result['filterType']]['msg'],

                'dataList' => $dataList,
                'filterInfo' => $currentTabMenuList[$result['filterType']]['filter_info'],
                'filter_type' => $result['filterType'],
                'infoUrl' => $this->returnInfoUrl(parent::MENU_ASSET_COO, ['type' => parent::MENU_ASSET_COO, 'flag' => $result['filterType']]),
                'pageCount' => $pageCount,
            ];
            if ($result['filterType'] == 1) {
                return view('web.asset.project', $viewData);
            } elseif ($result['filterType'] == 2) {
                return view('web.asset.money', $viewData);
            }

        }

    }
}
